package com.reborn.mall.api.common.util;

import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;

/**
 * TODO: Here is description
 *
 * @author wu.yue
 * @since 2020/2/7
 */
public class BeanUtil {

    public static <T> T copyProperties(Object source, Class<T> targetClass) {
        try {
            T target = targetClass.getConstructor().newInstance();
            BeanUtils.copyProperties(source, target);
            return target;
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("Bean copy properties failed");
        }
    }
}
